//弹窗 有确定与取消
(function ($, window, document, undefined) {
    $.extend({
        /* 提示框插件 */
        myAlert: function (opts) {
            this.defaults = {
            	type: 4, //弹出模式  1 定时关闭 2 确定取消  3 确定  4 无背景 5 加载中 
                title: "",  //标题
                text:"加载中···",    //内容
                width: 'auto',
                height: 'auto',
                textAlign: 'left',
                time: 2000,     //显示持续时间  
                isLock:false,   //是否锁屏  遮罩层                  
                sureFn: function(){     //确定回调
                   
                },   
                cancelFn: function(){   //取消回调
                    
                }
            };
            this.options = $.extend({}, this.defaults, opts);
            var _this = this;            
            var cssTxt = '';
            if(_this.options.type==4){
                cssTxt = 'width:'+ _this.options.width +';height:'+_this.options.height+';background-color:rgba(0,0,0,0);text-align:'+ _this.options.textAlign;
            }else{
                cssTxt = 'width:'+ _this.options.width +';height:'+_this.options.height+';text-align:'+ _this.options.textAlign;
            }
            var strHtml = '';
            	if(_this.options.type==4){
            		strHtml = '<div id="alertBox" class="alertBox tip" style="'+ cssTxt +'">';
            	}else if(_this.options.type==8){
            		strHtml = '<div id="alertBox" class="alertBox" style="'+ cssTxt +'"><span class="alert-close"></span>';
            	}else{
            		strHtml = '<div id="alertBox" class="alertBox" style="'+ cssTxt +'">';
            	}
                
            if(_this.options.title != ''){
                strHtml += '<div class="alertTitle">'+ _this.options.title +'</div>';
            }
                strHtml += '<div class="alertHtml">'+ _this.options.text +'</div>';
                strHtml += '<div class="alertBtn">';
            if( _this.options.type==2 ){
                strHtml += '<input id="alertBtn2" type="button" value="取消">';
                strHtml += '<input id="alertBtn1" type="button" value="确定">';
            }
            if( _this.options.type==3 ){
                strHtml += '<input id="alertBtn1" type="button" value="确定" style="margin-left:0">';
            }
            if( _this.options.type==6 ){
            	strHtml += '<span id="alertBtn2" class="aclose-btn">x</span>';
                strHtml += '<input id="alertBtn1" type="button" value="去购买">';
            }
            if( _this.options.type==7 ){
            	strHtml += '<input id="alertBtn2" type="button" value="取消">';
                strHtml += '<input id="alertBtn1" type="button" value="立即修改">';
            }
            if( _this.options.type==8 ){
            	strHtml += '<input id="alertBtn2" type="button" value="本月不再提醒">';
                strHtml += '<input id="alertBtn1" type="button" value="前往续保">';
            }
            strHtml += '</div></div>';
            if(_this.options.isLock){
                strHtml += '<div id="fixed" class="alerts"></div>';
            }  
            if($('#alertBox')||$('#fixed')){    //如果页面已经存在alert
                $('#alertBox').remove();
                $('#fixed').remove();
            }  
            if(_this.options.type==1){    
                $('body').append(strHtml);
                $('#alertBox').delay(_this.options.time).fadeOut(function(){
                    closeFn();
                });  
                $('#fixed').show();
            }else{
                $('body').append(strHtml);
                $('#alertBox').fadeIn();
                $('#fixed').show();
            }
            if(_this.options.type==4){
            	setTimeout(function(){
            		$('#alertBox').remove();
	                $('#fixed').delay(100).fadeOut(function(){
	                    $(this).remove();
	                })
            	},_this.options.time)
            }
            $('#alertBtn1').on('click',function(){
                _this.options.sureFn();
                closeFn();
            })
            $('#alertBtn2').on('click',function(){
                _this.options.cancelFn();
                closeFn();
            })
            function closeFn(){
                $('#alertBox').remove();
                $('#fixed').delay(100).fadeOut(function(){
                    $(this).remove();
                })
            }
            $("#fixed").on('touchstart',function(){
				closeFn();
			})
        }
    });
}(jQuery, window, document));